package main

import "fmt"

func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
	long := len(nums1) + len(nums2)
	var nums []int
	if len(nums1) == 0 || len(nums2) == 0 {
		nums = append(nums1, nums2...)
		if long%2 != 0 {
			return float64(nums[long/2])
		} else {
			var n float64
			n = float64(nums[long/2-1]+nums[long/2]) / 2.0
			return n
		}
	}
	a, b := 0, 0
	for i := 0; i < long/2+1; i++ {
		if nums1[a] >= nums2[b] {
			nums = append(nums, nums2[b])
			if b == len(nums2)-1 {
				nums = append(nums, nums1[a:]...)
				break
			}
			b++
		} else if nums2[b] > nums1[a] {
			nums = append(nums, nums1[a])
			if a == len(nums1)-1 {
				nums = append(nums, nums2[b:]...)
				break
			}
			a++
		}
	}
	if long%2 != 0 {
		return float64(nums[long/2])
	} else {
		var n float64
		n = float64(nums[long/2-1]+nums[long/2]) / 2.0
		return n
	}

}

func main() {
	//fmt.Println("2   :  ", findMedianSortedArrays([]int{1, 3}, []int{2}))
	//fmt.Println("4   :  ", findMedianSortedArrays([]int{1, 2, 5}, []int{3, 4, 6, 7}))
	//fmt.Println("2.50000   :  ", findMedianSortedArrays([]int{1, 2}, []int{3, 4}))
	fmt.Println("10000.5  :  ", findMedianSortedArrays([]int{100001}, []int{10000}))
	//a := []int{1, 2, 5}
	////fmt.Println(a[])
	//fmt.Println(a[0:])
	//fmt.Println(a[:1])
}
